package com.mingyizhudao.app.view.recommend;

import java.util.Map;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.dixiang.framework.common.QJNetUICallback;
import com.dixiang.framework.common.QjResult;
import com.dixiang.framework.widget.LoadingDialog;
import com.google.gson.reflect.TypeToken;
import com.mingyizhudao.app.R;
import com.mingyizhudao.app.entity.DeptEntity;
import com.mingyizhudao.app.utils.CommonUtils;
import com.mingyizhudao.app.utils.Constants;
import com.mingyizhudao.app.view.MYBaseActivity;

public class DeptIntroduceActivity extends MYBaseActivity implements
		OnClickListener {
	private String deptUrl, deptId, facultyName, hospitalName;

	private TextView dept_name, dept_introduce;
	private Button btn_order;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.activity_dept_introduce);
		super.onCreate(savedInstanceState);
		initView();
	}

	@Override
	public void initHeaderView() {

		initBackView(R.drawable.left_back_white_icon, 0, new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
	}

	private void initView() {
		
		hospitalName = getIntent().getStringExtra("hospitalName");
		deptUrl = getIntent().getStringExtra("deptUrl");
		facultyName = getIntent().getStringExtra("facultyName");
		deptId = getIntent().getStringExtra("deptId");
		setTitleViewValue(0, 0, R.color.white);
		// setTitleViewValue( hospitalName );

		dept_name = (TextView) findViewById(R.id.dept_name);
		dept_introduce = (TextView) findViewById(R.id.dept_introduce);
		btn_order = (Button) findViewById(R.id.btn_order);

		// dept_name.setText(facultyName);
		setTitleViewValue(facultyName);
		btn_order.setOnClickListener(this);

		getDeptIntro();
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_order:
			CommonUtils.goToCreateOrder(activity, deptId, null, facultyName,
					hospitalName, null, true);
			break;
		default:
			break;
		}
	}

	private void getDeptIntro() {
		LoadingDialog.getInstance(activity).show();
		getHttpResult(deptUrl, Constants.HTTP_INDEX.First, new TypeToken<QjResult<Map<String, DeptEntity>>>() {});
	}
	
	@Override
	public void onSuccess(QjResult result, String flg) {
		super.onSuccess(result, flg);
		Map<String, DeptEntity> map = (Map<String, DeptEntity>) result.getResults();
		if (map == null)
			return;
		DeptEntity deptEntity = map.get("department");
		if (deptEntity != null) {
			setTitleViewValue(deptEntity.getHpName());
			// dept_name.setText(deptEntity.getName());
			setTitleViewValue(deptEntity.getName());
			String des = deptEntity.getDescription();
			if (des != null && des.length() > 0) {
				dept_introduce.setText("科室介绍："
						+ deptEntity.getDescription());
			} else {
				dept_introduce.setText("暂无介绍");
			}

		} else {
			Toast.makeText(activity, "获取数据失败！", 0).show();
		}
	}
	
	@Override
	public void onCompleted(Exception e, String flg) {
		super.onCompleted(e, flg);
		LoadingDialog.getInstance(activity).dismiss();
	}

}
